package com.fyp.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.fyp.servlets.RequestResponse;

/*
 *  ============================================================================
 *  This file is part of 4YProject.
 *
 *  4YProject is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  4YProject is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with 4YProject; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  ============================================================================
 */

/**
 * ============================================================================
 * The following class DBInsert.java provides functionality that will allow the
 * servlets and jsp's to communicate with the database.
 * 
 * @version 1.0
 * @author Sean Crowley
 * @date 21 Jan 2008
 *       ============================================================================
 */

public class DBInsert {
	
	public static void main(String[] args) {
		DBInsert in = new DBInsert();
		try {
			in.establishConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void establishConnection() throws SQLException {
		RequestResponse req = new RequestResponse();
		String driver = "org.apache.derby.jdbc.EmbeddedDriver";
		String dbName = "/DerbyDB/AssetDB";
		String connectionURL = "jdbc:derby:" + dbName;
		Connection conn = null;
		try {
			Class.forName(driver);
		} catch (java.lang.ClassNotFoundException e) {
			e.printStackTrace();
		}

		try {
			conn = DriverManager.getConnection(connectionURL);
			Statement st = conn.createStatement();
			int m = st.executeUpdate("INSERT INTO USERS VALUES('Darragh','Crowley',9)");
//			int m = st.executeUpdate("INSERT INTO USERS VALUES("+"'"+req.getTitle()+"',"+"'"+req.getDescription()+"',10");
			System.out.println("Updated " + m + " rows");
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			conn.close();
		}
	}
}
